package camel.dsrawat.examples;

import org.apache.camel.CamelContext;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.spring.SpringCamelContext;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class EmailSender extends RouteBuilder{

	@Override
	public void configure() throws Exception {
		System.out.println("Email sent.");
		
		from("file:C:\\export\\mail\\in?noop=true").
		convertBodyTo(String.class).
		process(new Processor() {
			
			@Override
			public void process(Exchange arg0) throws Exception {
				System.out.println("Context:" + getContext());
				System.out.println("Exchange:"+arg0.getIn().getBody());
			}
		});

	}

	
	public static void main(String[] args) throws Exception {
		
		ApplicationContext appCtx = new ClassPathXmlApplicationContext("camel-config.xml");
		CamelContext ctx = new SpringCamelContext(appCtx);
		ctx.addRoutes((EmailSender)appCtx.getBean("testEmailSender"));
		
		ctx.start();
		Thread.sleep(10000);
		
	}
}
